#pragma once

#include "Hash.h"

namespace ether
{
	template<class K, class V, class Hash = Default_HashCode<K>>
	class unordered_map
	{
	public:
		struct Map_KeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};

		typedef typename HashBucket<K, pair<const K, V>, Map_KeyOfT, Hash>::iterator iterator;

		iterator begin()
		{
			return _hb.begin();
		}

		iterator end()
		{
			return _hb.end();
		}

		typedef typename HashBucket<K, pair<const K, V>, Map_KeyOfT, Hash>::const_iterator const_iterator;

		const_iterator begin() const
		{
			return _hb.begin();
		}

		const_iterator end() const
		{
			return _hb.end();
		}

		pair<iterator, bool> insert(const pair<K, V>& kv)
		{
			return _hb.insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = _hb.insert(make_pair(key, V()));
			return ret.first->second;
		}

		const V& operator[](const K& key) const
		{
			pair<iterator, bool> ret = _hb.insert(make_pair(key, V()));
			return ret.first->second;
		}

		iterator find(const K& key)
		{
			return _hb.find(key);
		}

		bool erase(const K& key)
		{
			return _hb.erase(key);
		}
	private:
		HashBucket<K, pair<const K, V>, Map_KeyOfT, Hash> _hb;
	};
}